from bs4 import BeautifulSoup
contents=''
with open('douban250.html','r',encoding='utf-8') as f:
    contents=f.read()
soup = BeautifulSoup(contents, 'lxml')
for tag in soup.find_all(attrs={"class": "item"}):
    # 爬取序号
    num = tag.find('em').get_text()
    print(num)
    # 电影名称
    name = tag.find_all(attrs={"class": "title"})
    if len(name)>1:
        zwname = name[0].get_text()
        print('[中文名称]', zwname)
        ywname = name[1].get_text().strip().replace('/','')
        print('[英文名称]', ywname)
    else:
        zwname = name[0].get_text()
        print('[中文名称]', zwname)
    # 网页链接
    url_movie = tag.find(attrs={"class": "hd"}).a
    urls = url_movie.attrs['href']
    print('[网页链接]', urls)
    # 爬取评分
    spans = tag.find(attrs={"class": "star"})
    star=spans.find(attrs={"class": "rating_num"}).get_text()
    print(star)
